package spynx.desl.runtime.impl;

import java.lang.reflect.Field;

import spynx.desl.runtime.IDataStorage;

public class FieldDataStorage implements IDataStorage {

	private Object obj;
	private Field field;

	public FieldDataStorage(Object obj, Field field) {
		this.obj = obj;
		this.field = field;
	}
	
	@Override
	public Object getValue() {
		try {
			return field.get(obj);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}

	@Override
	public void setValue(Object value) {
		try {
			field.set(obj, value);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

	@Override
	public boolean isReadOnly() {
		return false;
	}

	@Override
	public void setReadOnly(boolean readonly) {
	}

}
